<template>
  <div class="update-birthday">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close')"
      @confirm="onConfirm"
    />
  </div>
</template>
<script>
import {updategetUserProfile} from '@/api/user'
import dayjs from 'dayjs'
export default {
  name: "UpdateBirthday",
  data() {
    return {
      minDate: new Date(1990, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value),
    }
  },
  props: {
      value:{
          type:String,
          required:true
      }
  },
  methods: {
      async onConfirm () {
           this.$toast.loading({
           message:'保存中',
           forbidclick:true
       })
    //   `${this.currentDate.getFullYear()}-${this.currentDate.getMonth()+1}-${this.currentDate.getDate()}`
           const date=dayjs(this.currentDate).format('YYY-MM-DD')
           await updategetUserProfile({
              birthday:date
            })
            this.$toast.success('保存成功')
            this.$emit('input',this.defaultIndex)
            this.$emit('close')
      }
  }
};
</script>